#include <plc2llvm/Visitor/StrategyFactory.h>

StrategyFactory* StrategyFactory::factory = new StrategyFactory();

StrategyFactory::StrategyFactory() = default;

StrategyFactory *StrategyFactory::getFactory() {
    return StrategyFactory::factory;
}

void StrategyFactory::registerStrategy(int ruleIndex, Strategy *strategy) {
    StrategyFactory::factory->strategies.insert(std::make_pair(ruleIndex, strategy));
}

Strategy *StrategyFactory::getStrategy(int ruleIndex) {
    return StrategyFactory::factory->strategies[ruleIndex];
}

StrategyFactory::~StrategyFactory() {
    auto& strategyMap = this->strategies;
    for(auto strategyPair : strategyMap){
        Strategy* strategy = strategyPair.second;
        delete strategy;
    }
}
